package com.demo.gateway.userservice.controller;

import cn.hutool.core.util.ArrayUtil;
import com.demo.gateway.userservice.entity.Result;
import com.demo.gateway.userservice.entity.User;
import com.demo.gateway.userservice.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Value("${server.port}")
    String port;

    @Autowired
    UserService userService;

    /**
     * 获取用户服务的端口
     * @return
     */
    @GetMapping("/getUserPort")
    public String getUserPort() {
        return "user-service port：" + port;
    }

    /**
     * 获取用户服务的端口
     * @return
     */
//    @GetMapping("/getUser2")
//    public Result<List<User>> getUser2() {
//        return Result.success(userService.get2());
//    }
//
//    @GetMapping("/getById")
//    public Result<User> getById(@RequestParam String id) {
//        return Result.success(userService.queryById(id));
//    }

    @GetMapping("/getUser2")
    public Result<User> getUser2() {
        return Result.success(userService.get("1"));
    }

    @GetMapping("/getByIds")
    public Result<List<User>> getByIds() {
        return Result.success(userService.selectBatchIds(Arrays.asList("1","2")));
    }

    @GetMapping("/getList")
    public Result<List<User>> getList() {
        return Result.success(userService.getList());
    }

//    @GetMapping("/getById")
//    public Result<User> getById(@RequestParam String id) {
//        return Result.success(userService.queryById(id));
//    }

}
